package org.khd.base.service.impl;

import org.khd.base.mapper.BaseMapper;
import org.khd.base.query.BaseQuery;
import org.khd.base.service.IBaseService;
import org.khd.base.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void add(T t) {
        baseMapper.add(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void deleteById(Serializable id) {
        baseMapper.deleteById(id);
    }

    @Override
    public T queryById(Serializable id) {
        return baseMapper.queryById(id);
    }

    @Override
    public List<T> queryAll() {
        return baseMapper.queryAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        //用来查询T数据的总条数
        Long total = baseMapper.queryCount(query);
        //用来查询T每页的数据
        List<T> list = baseMapper.queryPage(query);
        return new PageList<>(total, list);
    }

    //批量删除T数据
    @Override
    public void patchDelete(List<Serializable> ids) {
        baseMapper.patchDelete(ids);
    }
}
